package com.lucker.service.caipiao;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lucker.cds.model.CCaiType;
import com.lucker.common.util.JiSuDataUtil;
import com.lucker.ds.mapper.BaseCustomMapper;
import com.lucker.ds.model.CaiType;
import com.lucker.framework.exception.BaseServiceException;
import com.lucker.service.BaseServiceImpl;

@Service
public class CaiTypeServiceImpl extends BaseServiceImpl<CaiType, CCaiType, Long> implements CaiTypeService {

	@Override
	public BaseCustomMapper<CCaiType, Long> getCustomMapper() {
		return null;
	}

	public void initCaiType() {
		String _caitype_json = null;
		try {
			_caitype_json = JiSuDataUtil.getCaiPiaoList();
		}catch (Exception e) {
			getLOGGER().error("获取彩票分类错误 : {} , {}",e,e.getMessage());
			throw new BaseServiceException("获取彩票分类错误");
		}
		
		JSONObject _json = JSON.parseObject(_caitype_json);
		if(_json != null && _json.containsKey("result")) {
			
			JSONArray _array = _json.getJSONArray("result");
			for(int i = 0 ; i < _array.size() ; i++) {
				JSONObject _type_object = _array.getJSONObject(i);
				
				if(_type_object != null && _type_object.containsKey("parentid") && _type_object.getInteger("parentid") == 0) {
					CaiType _caiType = new CaiType();
					_caiType.setCaiTypeId(_type_object.getString("caipiaoid"));
					int count = this.getBaseMapper().selectAllCount(_caiType);
					if(count < 1) {
						_caiType.setCaiTypeName(_type_object.getString("name"));
//						this.getBaseMapper().insert(_caiType);
						this.queryAll(_caiType);
					}				
					
				}
			}
		}
		
		
		
		
		
		
		
	}
}
